package com.socialuni.center.web.factory;

import com.socialuni.sdk.api.model.RO.user.base.SocialUserFollowDetailRO;
import com.socialuni.center.web.model.RO.user.CenterUserFollowDetailRO;
import com.socialuni.center.web.utils.UnionIdDbUtil;
import com.socialuni.sdk.constant.FollowConst;
import com.socialuni.sdk.factory.ListConvertUtil;
import com.socialuni.sdk.factory.user.base.SocialFollowUserROFactory;
import com.socialuni.sdk.model.DO.user.UserDO;

import java.util.List;

/**
 * @author qinkaiyuan 查询结果可以没有set和空构造，前台传值可以没有get
 * @date 2019-08-13 23:34
 */
public class CenterUserFollowDetailROFactory {
    public static CenterUserFollowDetailRO newCenterFollowUserRO(UserDO userDO, UserDO mineUser) {
        //user基础信息
        SocialUserFollowDetailRO socialUserDetailFollowRO = SocialFollowUserROFactory.newSocialFollowUserRO(userDO, mineUser);
        CenterUserFollowDetailRO centerFollowUserRO = new CenterUserFollowDetailRO(socialUserDetailFollowRO);

        String userUId = UnionIdDbUtil.createUserUid(socialUserDetailFollowRO.getId());
        centerFollowUserRO.setId(userUId);
        //应该移动到前端
        if (centerFollowUserRO.getHasFollowed()) {
            if (centerFollowUserRO.getBeFollow()) {
                centerFollowUserRO.setFollowStatus(FollowConst.eachFollow);
            } else {
                centerFollowUserRO.setFollowStatus(FollowConst.followed);
            }
        } else {
            centerFollowUserRO.setFollowStatus(FollowConst.follow);
        }
        return centerFollowUserRO;
    }

    public static List<CenterUserFollowDetailRO> newUsers(List<UserDO> users, UserDO mineUser) {
        return ListConvertUtil.toList(users, CenterUserFollowDetailROFactory::newCenterFollowUserRO, mineUser);
    }
}
